package com.homwee.factory.pageData;

import java.io.File;
import java.util.ArrayList;

import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.UserHandle;
import android.util.Log;
import android.widget.Toast;

import com.homwee.factory.FactoryActivity;
import com.homwee.factory.R;
import com.homwee.factory.util.Contants;
import com.homwee.listMenu.util.MenuItemData;
//import com.changhong.tvos.atv.ATVChannelManager;
//import com.changhong.tvos.common.exception.ChannelNotFoundException;
//import com.changhong.tvos.model.ATVChannelInfo;
//import com.changhong.tvos.model.ChOsType.EnumColorSystem;
//import com.changhong.tvos.model.ChOsType.EnumSoundSystem;
//zcj 2018-10-30 import com.changhong.tvos.service.TvMiscManager;
import com.mediatek.twoworlds.factory.MtkTvFApiSystem;
import com.mediatek.twoworlds.factory.common.MtkTvFApiInputSourceTypes;

public class PageData3 extends PageData {
	String TAG = "Factory3";
	List<MenuItemData> mSubList_VIF = new ArrayList<MenuItemData>();
	List<MenuItemData> mSubList_VD = new ArrayList<MenuItemData>();

	private static final int BASE_SCRAMBLE_BOX_DELAY_VAL = 418;

	private static final int MAX_SCRAMBLE_BOX_DELAY_VAL = 468;

	private static final int MIN_SCRAMBLE_BOX_DELAY_VAL = 368;

	private Handler mHandler = new Handler();

	private Context context;
	private MtkTvFApiSystem mMtkTvFApiSystem;

	public PageData3(Context context, FactoryActivity mFactoryActivity) {
		super(mFactoryActivity);
		this.context = context;
		mMtkTvFApiSystem=MtkTvFApiSystem.getInstance();
	}

	public List<MenuItemData> LoadPageData() {
		mListItemData.clear();
		mSubList_VIF.clear();
		mSubList_VD.clear();
		String[] pictureStr = { "picture0", "picture1", "picture2", "picture3",
				"picture4" };

		String analogDigitalScanStr = mFactoryActivity.getResources()
				.getString(R.string.factory_analog_channel_scan);
		MenuItemData analogDigitalScan = new MenuItemData(analogDigitalScanStr);
		analogDigitalScan.setOnEnterKey(new MenuItemData.onEnterRightKey() {

			public void onEnterRightKey() {
				// TODO Auto-generated method stub
				Log.v("tv", "onEnterRightKey");
				// Intent scanIntent = new
				// Intent("com.changhong.tvap.atv.activity.AtvMainActivity");
				// scanIntent .putExtra("searchId", "factoryMenu");
				// scanIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				// mContext.startActivity(scanIntent);

				// mTvChannelManager.setUserScanType(TvChannelManager.TV_SCAN_ALL);
				factorySetting.setATVDTVAllSearchMode();
				Intent intent = new Intent();// com.changhong.tvplayer.activity
				intent.setClassName("com.mediatek.wwtv.tvcenter",
						"com.mediatek.wwtv.setting.base.scan.ui.ScanDialogActivity");
				intent.putExtra("ActionID", "channel_scan");
				mContext.startActivity(intent);

			}
		});

		String channelSettingStr = mFactoryActivity.getResources().getString(
				R.string.factory_analog_channel_setting);
		MenuItemData channelSetting = new MenuItemData(channelSettingStr);
		channelSetting.setOnEnterKey(new MenuItemData.onEnterRightKey() {

			public void onEnterRightKey() {
				// TODO Auto-generated method stub
				// mFactoryActivity.showMenu(false);
				Log.v("tv", "Factory Preset Channel");
				mHandler.post(new Runnable() {
					public void run() {
						final File tvDatabase = new File("/chperm/tvdatabase");
						if (tvDatabase.exists()) {
							if (tvDatabase.listFiles() == null) {
								Toast.makeText(context,
										"file directory permission error!",
										Toast.LENGTH_SHORT).show();
								return;
							}
							final File[] channel_files = tvDatabase.listFiles();

							if (channel_files.length == 0) {
								Toast toast = Toast
										.makeText(
												context,
												"Can't find any file in /chperm/tvdatabase directory!",
												Toast.LENGTH_SHORT);
								toast.show();
							} else {
								new Handler().postDelayed(new Runnable() {

									@Override
									public void run() {
										// TODO Auto-generated method stub
										for (File file : channel_files) {

											factorySetting.copyFile(
													file.getAbsolutePath(),
													"/tvdatabase/Database"
															+ File.separator
															+ file.getName());
										}
										Toast.makeText(
												context,
												"Successful to preset channel! ",
												Toast.LENGTH_SHORT).show();
										// PowerManager pManager=(PowerManager)
										// mContext.getSystemService(mContext.POWER_SERVICE);
										// pManager.reboot("");
									}
								}, 100);
							}
						} else {
							Toast.makeText(context,
									"Can't find factory channel directory!",
									Toast.LENGTH_SHORT).show();
						}

					}

				});
				// Intent intent = new Intent();
				// Intent settingMenuIntent = new
				// Intent(mFactoryActivity,FactoryChannelInitActivity.class);
				// mFactoryActivity.startActivity(settingMenuIntent);
			}
		});

		MenuItemData ClientPresetChannel = new MenuItemData(
				"Preset Client Channel");
		ClientPresetChannel.setOnEnterKey(new MenuItemData.onEnterRightKey() {

			public void onEnterRightKey() {
				// TODO Auto-generated method stub
				// mFactoryActivity.showMenu(false);
				Log.v("tv", "Client Preset Channel");
				mHandler.post(new Runnable() {
					public void run() {
						final File tvDatabase = new File(
								"/chperm/client_tvdatabase");
						if (tvDatabase.exists()) {
							if (tvDatabase.listFiles() == null) {
								Toast.makeText(context,
										"file directory permission error!",
										Toast.LENGTH_SHORT).show();
								return;
							}
							final File[] channel_files = tvDatabase.listFiles();

							if (channel_files.length == 0) {
								Toast toast = Toast
										.makeText(
												context,
												"Can't find any file in /chperm/client_tvdatabase directory!",
												Toast.LENGTH_SHORT);
								toast.show();
							} else {
								new Handler().postDelayed(new Runnable() {

									@Override
									public void run() {
										// TODO Auto-generated method stub
										for (File file : channel_files) {

											factorySetting.copyFile(
													file.getAbsolutePath(),
													"/tvdatabase/Database"
															+ File.separator
															+ file.getName());
										}
										Toast.makeText(
												context,
												"Successful to preset channel! ",
												Toast.LENGTH_SHORT).show();
										// PowerManager pManager=(PowerManager)
										// mContext.getSystemService(mContext.POWER_SERVICE);
										// pManager.reboot("");

										/* add by ARTHUR 2018-7-13 */
										factorySetting
												.systemInitForPresetClientChannel();
									}
								}, 100);

								/*
								 * FactoryToast toast = new
								 * FactoryToast(context);
								 * toast.setDuration(5000);
								 * toast.setToastIcon(R.drawable.pic_eye);
								 * toast.setMessage(context.getString(R.string.
								 * factory_system_reset));
								 * toast.getTextView().getBackground
								 * ().setAlpha(200); toast.show();
								 * 
								 * new Handler().postDelayed(new Runnable() {
								 * 
								 * @Override public void run() { // TODO
								 * Auto-generated method stub add by ARTHUR
								 * 2018-7-13
								 * factorySetting.systemInitForPresetClientChannel
								 * (); } }, 2000);
								 */

							}
						} else {
							Toast.makeText(context,
									"Can't find client channel directory!",
									Toast.LENGTH_SHORT).show();
						}
					}

				});
			}
		});

		MenuItemData ExportChannel = new MenuItemData("Export Channel");
		ExportChannel.setOnEnterKey(new MenuItemData.onEnterRightKey() {

			public void onEnterRightKey() {
				// TODO Auto-generated method stub
				if (factorySetting.findUsbDir()) {
					///File file=factorySetting.getFile(Contants.FACTORY_CHANNEL_LIST_PATH_USB);
					//if(mMtkTvFApiSystem.isFileExist(file.getAbsolutePath())){
						//Log.d(TAG,file.getAbsolutePath());
						//factorySetting.dumpFactoryChannelListByPath(1,file.getAbsolutePath());
					//}
					int tmpint=factorySetting.dumpChannelList(1);
					Toast.makeText(
							context,
							tmpint==0?mContext.getString(R.string.factory_pageall_success)
									:mContext.getString(R.string.factory_pageall_error),
							Toast.LENGTH_SHORT).show();
				} else {
					Toast.makeText(
							context,
							mContext.getString(R.string.factory_reciver_no_usb),
							Toast.LENGTH_SHORT).show();
				}
			}
		});

		MenuItemData ImportChannel = new MenuItemData("Import Channel");
		ImportChannel.setOnEnterKey(new MenuItemData.onEnterRightKey() {

			public void onEnterRightKey() {
				// TODO Auto-generated method stub
				if (factorySetting.findUsbDir()) {
					if (factorySetting.getFile(Contants.PATH_CHANNEL).exists()) {
						broadcastIntentOut("mtk.intent.event.preset.channel.start");
						//int tmpint=factorySetting.loadFactoryChannelListByPath(1,Contants.FACTORY_CHANNEL_LIST_PATH_TV);
						int tmpint=factorySetting.loadChannelList(1);
						broadcastIntentOut("mtk.intent.event.preset.channel.end");
						if(tmpint == 0)
						{
							Toast.makeText(
									context, mContext.getString(R.string.factory_pageall_success),
									Toast.LENGTH_SHORT).show();
							factorySetting.selectfirstChannel();
						}else{
							Toast.makeText(
									context, mContext.getString(R.string.factory_pageall_error),
									Toast.LENGTH_SHORT).show();
						}

					}
					else {
						Toast.makeText(
								context,
								mContext.getString(R.string.factory_pagethree_channellist_folder_no_exits),
								Toast.LENGTH_SHORT).show();
					}
					
				} else {
					Toast.makeText(
							context,
							mContext.getString(R.string.factory_reciver_no_usb),
							Toast.LENGTH_SHORT).show();
				}
			}
		});

		String[] colorModeArray = mFactoryActivity.getResources()
				.getStringArray(R.array.factoryTuneSettingColorMode);
		String colorModeStr = mFactoryActivity.getResources().getString(
				R.string.factory_tune_setting_color_mode);
		MenuItemData pictureMode = new MenuItemData(0, colorModeStr, 0, 3, 0,
				colorModeArray, 1, MenuItemData.EN_ItemType.EN_OPTIONVIEW);
		try {
			// zcj 2018-10-30 pictureMode.mInitValue
			// =factorySetting.getColorMode().ordinal();
			pictureMode.mInitValue = 1;
		} catch (Exception e2) {
			// TODO Auto-generated catch block
			e2.printStackTrace();
		}
		pictureMode.setOnValueChange(new MenuItemData.onValueChange() {

			public void valueChange(int value) {
				// TODO Auto-generated method stub
				Log.v("tv", "pictureMode");
				try {
					factorySetting.setColorMode(value);
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});

		String[] audioModeArray = mFactoryActivity.getResources()
				.getStringArray(R.array.factoryTuneSettingAudioMode);
		String audioModeStr = mFactoryActivity.getResources().getString(
				R.string.factory_tune_setting_audio_mode);
		MenuItemData audioMode = new MenuItemData(0, audioModeStr, 0, 3, 0,
				audioModeArray, 1, MenuItemData.EN_ItemType.EN_OPTIONVIEW);
		try {
			// zcj 2018-10-30 audioMode.mInitValue
			// =factorySetting.getAudioMode().ordinal();
			audioMode.mInitValue = 1;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		audioMode.setOnValueChange(new MenuItemData.onValueChange() {

			public void valueChange(int value) {
				// TODO Auto-generated method stub
				Log.v("tv", "audioMode");
				value += 1;
				try {
					factorySetting.setAudioMode(value);
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});

		String[] MuteColorArray = {  "White", "Red", "Green","Blue", "Black" };
		MenuItemData MuteColor = new MenuItemData(0, "Mute Color", 0,
				MuteColorArray.length - 1, 0, MuteColorArray, 1,
				MenuItemData.EN_ItemType.EN_OPTIONVIEW);
		try {
			MuteColor.mInitValue = factorySetting.getMuteColerIndex();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		MuteColor.setOnValueChange(new MenuItemData.onValueChange() {

			public void valueChange(int value) {
				// TODO Auto-generated method stub
				Log.v("tv", "MuteColor" + value);

				try {
					factorySetting.setMuteColerIndex(value);
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});

		final MenuItemData tunerSel = new MenuItemData(0, "Tuner", 0, 0, 0,
				"Tuner", 1);

		tunerSel.updateValue(factorySetting.getTunerName());

		MenuItemData Nonstandard_VIF = new MenuItemData("Non-standard VIF");
		MenuItemData Nonstandard_VD = new MenuItemData("Non-standard VD");
		

		// VIF 9

		MenuItemData VIF_AgcRef = new MenuItemData(0, "VIF_AGC_REF", 0x20,
				0x80, 0x60, 1, MenuItemData.EN_ItemType.EN_OPTIONVIEW);
		VIF_AgcRef.setOnValueChange(new MenuItemData.onValueChange() {

			public void valueChange(int value) {
				// TODO Auto-generated method stub
				Log.v(TAG, "setAtvNonstdVif_AgcRef" + value);
				factorySetting.setAtvNonstdVif_AgcRef(value);
			}
		});
/*
		MenuItemData VIF_CrKp = new MenuItemData(0, "VIF_CR_KP", 0, 255, 1, 1,
				MenuItemData.EN_ItemType.EN_OPTIONVIEW);
		VIF_CrKp.setOnValueChange(new MenuItemData.onValueChange() {

			public void valueChange(int value) {
				// TODO Auto-generated method stub
				Log.v(TAG, "setAtvNonstdVif_CrKp" + value);
				factorySetting.setAtvNonstdVif_CrKp(value);
			}
		});

		MenuItemData VIF_CrKi = new MenuItemData(0, "VIF_CR_KI", 0, 255, 1, 1,
				MenuItemData.EN_ItemType.EN_OPTIONVIEW);
		VIF_CrKi.setOnValueChange(new MenuItemData.onValueChange() {

			public void valueChange(int value) {
				// TODO Auto-generated method stub
				Log.v(TAG, "setAtvNonstdVif_CrKi" + value);
				factorySetting.setAtvNonstdVif_CrKi(value);
			}
		});
*/
		MenuItemData VIF_AsiaSignalOption = new MenuItemData(0,
				"VIF_ASIA_SIGNAL_OPTION", 0, 1, 0, mFactoryActivity
						.getResources().getStringArray(
								R.array.factoryCloseOrOpen), 1,
				MenuItemData.EN_ItemType.EN_OPTIONVIEW);
		VIF_AsiaSignalOption.setOnValueChange(new MenuItemData.onValueChange() {

			public void valueChange(int value) {
				// TODO Auto-generated method stub
				Log.v(TAG, "setAtvNonstdVif_AsiaSignalOption" + value);
				factorySetting.setAtvNonstdVif_AsiaSignalOption(value);
			}
		});

		MenuItemData VIF_ClampGainOVNegative = new MenuItemData(0,
				"VIF_CLAMPGAIN_OV_NEGATIVE", 0, 0x7ff, 0x600, 16,
				MenuItemData.EN_ItemType.EN_OPTIONVIEW);
		VIF_ClampGainOVNegative.mInitValue = factorySetting
				.getAtvNonstdVif_ClampGainOvNegative();
		VIF_ClampGainOVNegative
				.setOnValueChange(new MenuItemData.onValueChange() {

					public void valueChange(int value) {
						// TODO Auto-generated method stub
						Log.v(TAG, "setAtvNonstdVif_AsiaSignalOption" + value);
						factorySetting
								.setAtvNonstdVif_ClampGainOvNegative(value);
					}
				});

		MenuItemData VIF_ChinaDESBoxDelay = new MenuItemData(0,
				"CHINA_DES_BOX_DELAY", -50, 50, 0, 1, MenuItemData.EN_ItemType.EN_OPTIONVIEW);
		
		VIF_ChinaDESBoxDelay.setOnValueChange(new MenuItemData.onValueChange() {

			public void valueChange(int value) {
				// TODO Auto-generated method stub
				Log.v(TAG, "setAtvNonstdVif_ChinaDescramblerBoxDelay" + value);
				factorySetting.setAtvNonstdVif_ChinaDescramblerBoxDelay(value);

			}
		});

		MenuItemData VIF_CrThr = new MenuItemData(0, "VIF_CR_THR", 0x70, 0x500,
				0x500, 2, MenuItemData.EN_ItemType.EN_OPTIONVIEW);
		VIF_CrThr.setOnValueChange(new MenuItemData.onValueChange() {

			public void valueChange(int value) {
				// TODO Auto-generated method stub
				Log.v(TAG, "setAtvNonstdVif_CrThreshold" + value);
				factorySetting.setAtvNonstdVif_CrThreshold(value);
			}
		});

		MenuItemData VIF_Delay = new MenuItemData(0, "Delay", 0, 255, 1, 1,
				MenuItemData.EN_ItemType.EN_OPTIONVIEW);
		VIF_Delay.mInitValue = factorySetting.getAtvNonstdVif_DelayReduce();
		VIF_Delay.setOnValueChange(new MenuItemData.onValueChange() {

			public void valueChange(int value) {
				// TODO Auto-generated method stub
				Log.v(TAG, "setAtvNonstdVif_DelayReduce" + value);
				factorySetting.setAtvNonstdVif_DelayReduce(value);
			}
		});

		MenuItemData VIF_Version = new MenuItemData(0, "VIF_VERSION", 0, 255,
				1, 1, MenuItemData.EN_ItemType.EN_OPTIONVIEW);
		VIF_Version.mInitValue = factorySetting.getAtvNonstdVif_VifVersion();
		VIF_Version.setOnValueChange(new MenuItemData.onValueChange() {

			public void valueChange(int value) {
				// TODO Auto-generated method stub
				Log.v(TAG, "setAtvNonstdVif_VifVersion" + value);
				factorySetting.setAtvNonstdVif_VifVersion(value);
			}
		});

		//initVIF
		MtkTvFApiInputSourceTypes.StructVifParams vifParams=factorySetting.getVifParams();
		VIF_AgcRef.mInitValue = vifParams.vifAgcRef;
		//VIF_CrKp.mInitValue = vifParams.vifCrKp;
		//VIF_CrKi.mInitValue = vifParams.vifCrKi;
		VIF_AsiaSignalOption.mInitValue = vifParams.vifAsiaOption?1:0;
		VIF_CrThr.mInitValue = (int)vifParams.vifCrThreshold;
		VIF_ChinaDESBoxDelay.mInitValue= vifParams.vifChinaDescramblerBoxDelay;
		
		// VD

		MenuItemData VD_AfecD4 = new MenuItemData(0, "AFEC_D4", 0, 255, 1, 1,
				MenuItemData.EN_ItemType.EN_OPTIONVIEW);
		VD_AfecD4.mInitValue = factorySetting.getAtvNonstdVD_AefcD4();
		VD_AfecD4.setOnValueChange(new MenuItemData.onValueChange() {

			public void valueChange(int value) {
				// TODO Auto-generated method stub
				Log.v(TAG, "setAtvNonstdVD_AefcD4" + value);
				factorySetting.setAtvNonstdVD_AefcD4(value);
			}
		});

		MenuItemData VD_AfecD5_2 = new MenuItemData(0, "AFEC_D5[2]", 0, 1, 0,
				1, MenuItemData.EN_ItemType.EN_OPTIONVIEW);
		VD_AfecD5_2.mInitValue = factorySetting.getAtvNonstdVD_AefcD5Bit2();
		VD_AfecD5_2.setOnValueChange(new MenuItemData.onValueChange() {

			public void valueChange(int value) {
				// TODO Auto-generated method stub
				Log.v(TAG, "setAtvNonstdVD_AefcD5Bit2" + value);
				factorySetting.setAtvNonstdVD_AefcD5Bit2(value);
			}
		});

		MenuItemData VD_AfecD8_3210 = new MenuItemData(0, "AFEC_D8[3:0]", 0,
				15, 0, 1, MenuItemData.EN_ItemType.EN_OPTIONVIEW);
		VD_AfecD8_3210.mInitValue = factorySetting
				.getAtvNonstdVD_AefcD8Bit3210();
		VD_AfecD8_3210.setOnValueChange(new MenuItemData.onValueChange() {

			public void valueChange(int value) {
				// TODO Auto-generated method stub
				Log.v(TAG, "setAtvNonstdVD_AefcD8Bit3210" + value);
				factorySetting.setAtvNonstdVD_AefcD8Bit3210(value);
			}
		});

		MenuItemData VD_AfecD9_0 = new MenuItemData(0, "AFEC_D9[0]", 0, 1, 0,
				1, MenuItemData.EN_ItemType.EN_OPTIONVIEW);
		VD_AfecD9_0.mInitValue = factorySetting.getAtvNonstdVD_AefcD9Bit0();
		VD_AfecD9_0.setOnValueChange(new MenuItemData.onValueChange() {

			public void valueChange(int value) {
				// TODO Auto-generated method stub
				Log.v(TAG, "setAtvNonstdVD_AefcD9Bit0" + value);
				factorySetting.setAtvNonstdVD_AefcD9Bit0(value);
			}
		});

		MenuItemData VD_AfecD7_HighBoun = new MenuItemData(0,
				"AFEC_D7_HIGH_BOUN", 0, 255, 0, 1, MenuItemData.EN_ItemType.EN_OPTIONVIEW);
		VD_AfecD7_HighBoun.mInitValue = factorySetting
				.getAtvNonstdVD_AefcD7HighBound();
		VD_AfecD7_HighBoun.setOnValueChange(new MenuItemData.onValueChange() {

			public void valueChange(int value) {
				// TODO Auto-generated method stub
				Log.v(TAG, "setAtvNonstdVD_AefcD7HighBound" + value);
				factorySetting.setAtvNonstdVD_AefcD7HighBound(value);
			}
		});

		MenuItemData VD_AfecD7_LowBoun = new MenuItemData(0,
				"AFEC_D7_LOW_BOUN", 0, 255, 0, 1, MenuItemData.EN_ItemType.EN_OPTIONVIEW);
		VD_AfecD7_LowBoun.mInitValue = factorySetting
				.getAtvNonstdVD_AefcD7LowBound();
		VD_AfecD7_LowBoun.setOnValueChange(new MenuItemData.onValueChange() {

			public void valueChange(int value) {
				// TODO Auto-generated method stub
				Log.v(TAG, "setAtvNonstdVD_AefcD7LowBound" + value);
				factorySetting.setAtvNonstdVD_AefcD7LowBound(value);
			}
		});

		MenuItemData VD_AfecA0 = new MenuItemData(0, "AFEC_A0", 0, 255, 0, 1,
				MenuItemData.EN_ItemType.EN_OPTIONVIEW);
		VD_AfecA0.mInitValue = factorySetting.getAtvNonstdVD_AefcA0();
		VD_AfecA0.setOnValueChange(new MenuItemData.onValueChange() {

			public void valueChange(int value) {
				// TODO Auto-generated method stub
				Log.v(TAG, "setAtvNonstdVD_AefcA0" + value);
				factorySetting.setAtvNonstdVD_AefcA0(value);
			}
		});

		MenuItemData VD_AfecA1 = new MenuItemData(0, "AFEC_A1", 0, 255, 0, 1,
				MenuItemData.EN_ItemType.EN_OPTIONVIEW);
		VD_AfecA1.mInitValue = factorySetting.getAtvNonstdVD_AefcA1();
		VD_AfecA1.setOnValueChange(new MenuItemData.onValueChange() {

			public void valueChange(int value) {
				// TODO Auto-generated method stub
				Log.v(TAG, "setAtvNonstdVD_AefcA1" + value);
				factorySetting.setAtvNonstdVD_AefcA1(value);
			}
		});

		MenuItemData VD_Afec66_76 = new MenuItemData(0, "AFEC_66[7:6]", 0, 3,
				0, 1, MenuItemData.EN_ItemType.EN_OPTIONVIEW);
		VD_Afec66_76.mInitValue = factorySetting.getAtvNonstdVD_Aefc66Bit76();
		VD_Afec66_76.setOnValueChange(new MenuItemData.onValueChange() {

			public void valueChange(int value) {
				// TODO Auto-generated method stub
				Log.v(TAG, "setAtvNonstdVD_Aefc66Bit76" + value);
				factorySetting.setAtvNonstdVD_Aefc66Bit76(value);
			}
		});

		MenuItemData VD_Afec6e_74 = new MenuItemData(0, "AFEC_6E[7:4]", 0, 15,
				0, 1, MenuItemData.EN_ItemType.EN_OPTIONVIEW);
		VD_Afec6e_74.mInitValue = factorySetting.getAtvNonstdVD_Aefc6EBit7654();
		VD_Afec6e_74.setOnValueChange(new MenuItemData.onValueChange() {

			public void valueChange(int value) {
				// TODO Auto-generated method stub
				Log.v(TAG, "setAtvNonstdVD_Aefc6EBit7654" + value);
				factorySetting.setAtvNonstdVD_Aefc6EBit7654(value);
			}
		});

		//Record all
		MenuItemData recordAll=new MenuItemData(0,"Record All",0,1,0,1,MenuItemData.EN_ItemType.EN_OPTIONVIEW);
		recordAll.mInitValue=factorySetting.getRecordAll();
		recordAll.setOnValueChange(new MenuItemData.onValueChange() {
			@Override
			public void valueChange(int value) {
				Log.d(TAG,"setRecordAll:"+value);
				factorySetting.setRecordAll(value);
			}
		});

		mListItemData.add(analogDigitalScan);
		mListItemData.add(ExportChannel);
		mListItemData.add(ImportChannel);
		//2018-11-28 mListItemData.add(channelSetting);
		//mListItemData.add(pictureMode);
		//mListItemData.add(audioMode);

		mListItemData.add(MuteColor);
		mListItemData.add(recordAll);

		//mListItemData.add(tunerSel);
		//2018-11-28 mListItemData.add(ClientPresetChannel);

		// mListItemData.add(CheckRFFilter);
		mListItemData.add(Nonstandard_VIF);
		mListItemData.add(Nonstandard_VD);

		// vif
		mSubList_VIF.add(VIF_AgcRef);
//		mSubList_VIF.add(VIF_CrKp);
//		mSubList_VIF.add(VIF_CrKi);
		mSubList_VIF.add(VIF_AsiaSignalOption);
		mSubList_VIF.add(VIF_ChinaDESBoxDelay);
		mSubList_VIF.add(VIF_CrThr);
		mSubList_VIF.add(VIF_Delay);
		mSubList_VIF.add(VIF_Version);

		VIF_AgcRef.mParentGroup = mListItemData;
		VIF_AgcRef.mParent = Nonstandard_VIF;
		Nonstandard_VIF.mSubChildGroup = mSubList_VIF;

		// VD
		mSubList_VD.add(VD_AfecD4);
		mSubList_VD.add(VD_AfecD5_2);
		mSubList_VD.add(VD_AfecD8_3210);
		mSubList_VD.add(VD_AfecD9_0);
		mSubList_VD.add(VD_AfecD7_HighBoun);
		mSubList_VD.add(VD_AfecD7_LowBoun);

		mSubList_VD.add(VD_AfecA0);
		mSubList_VD.add(VD_AfecA1);

		mSubList_VD.add(VD_Afec66_76);
		mSubList_VD.add(VD_Afec6e_74);

		VD_AfecD4.mParentGroup = mListItemData;
		VD_AfecD4.mParent = Nonstandard_VD;
		Nonstandard_VD.mSubChildGroup = mSubList_VD;

		

		return mListItemData;
	}

	public void initATVChannelTable() {
		factorySetting.initATVChannelTable(true);
	}

	@SuppressLint("NewApi")
	private void broadcastIntentOut(String broadcastType) {
		try {
			synchronized (FactoryActivity.class) {
				Intent intent = new Intent();

				intent.setAction(broadcastType);
				mContext.sendBroadcastAsUser(intent,
						UserHandle.getUserHandleForUid(1000));
				Log.d(TAG, "broadcastIntentOut==>do broadcast broadcastType="
						+ broadcastType);
			}
		} catch (Exception e) {
			Log.d(TAG, "RemoteException:" + e.getMessage());
		}
	}
}
